
*14 year olds
gen year14=birthyear+13


gen x_period=0
replace x_period =1 if year14>1993





gen x_mandalcasteyear=0
replace x_mandalcasteyear=1 if x_period==1 &stategrp==1&castgrp==1
replace x_mandalcasteyear=. if year14==1991 &obc_res_year==1991&castgrp==1
replace x_mandalcasteyear=. if year14==1992 &obc_res_year==1991&castgrp==1
replace x_mandalcasteyear=. if year14==1993 &obc_res_year==1991&castgrp==1

gen x_yearmandal=0
replace x_yearmandal=1 if x_period==1 &stategrp==1
replace x_yearmandal=. if year14==1991 &obc_res_year==1991
replace x_yearmandal=. if year14==1992 &obc_res_year==1991
replace x_yearmandal=. if year14==1993 &obc_res_year==1991

gen x_casteyear=year14*10+ caste4
gen x_stateyear=STATEID*100+(year14-1947)

gen x_state_res_year=0
replace x_state_res_year=1 if year14>=obc_res_year


*continous
gen x_res_prop=0
replace x_res_prop=obcquota/stateobc if x_state_res_year==1
replace x_res_prop=20/stateobc if state=="Bihar" &year14 >=1977  &year14<1992
replace x_res_prop=20/stateobc if state=="Jharkhand" &year14>=1977  &year14<1993
replace x_res_prop=33/stateobc if state=="Jharkhand" &year14>= 1992 &year14<2000
replace x_res_prop=35/stateobc if state=="Karnataka" &year14>=1977  &year14<1996
replace x_res_prop=55/stateobc if state=="Karnataka" &year14>=1986  &year14<1994
replace x_res_prop=14/stateobc if state=="Maharashtra" &year14>=1947  &year14<1994
replace x_res_prop=30/stateobc if state=="Maharashtra" &year14>= 1994 &year14<1995
replace x_res_prop=5/stateobc if state=="Punjab" &year14>=1964  &year14<1993
replace x_res_prop=25/stateobc if state=="Tamil Nadu" &year14>=1947  &year14<1971
replace x_res_prop=31/stateobc if state=="Tamil Nadu" &year14>=1971  &year14<1980
replace x_res_prop=27/stateobc if state=="Uttarakhand" &year14>=1993  &year14<2000


gen x_res_prop_obc=obc*x_res_prop

gen x_int_obc=castgr 
gen x_int_post94=x_period
gen x_int_northstate=stategr
gen x_int_obc_north=castgr *stategr
gen x_int_obc_post94=castgr*x_period
gen x_int_north_post94=stategr*x_period
gen x_int_north_obc_post=castgr *stategr*x_period
gen x_obc_post79=0
replace x_obc_post79=1 if year14>1979&obc==1
gen x_north_post79=0
replace x_north_post79=1 if year14>1979&stategr==1



*10 year olds
gen year10=birthyear+9

gen q_period=0
replace q_period =1 if year10>1993






gen q_mandalcasteyear=0
replace q_mandalcasteyear=1 if q_period==1 &stategrp==1&castgrp==1
replace q_mandalcasteyear=. if year10==1991 &obc_res_year==1991&castgrp==1
replace q_mandalcasteyear=. if year10==1992 &obc_res_year==1991&castgrp==1
replace q_mandalcasteyear=. if year10==1993 &obc_res_year==1991&castgrp==1

gen q_yearmandal=0
replace q_yearmandal=1 if q_period==1 &stategrp==1
replace q_yearmandal=. if year10==1991 &obc_res_year==1991
replace q_yearmandal=. if year10==1992 &obc_res_year==1991
replace q_yearmandal=. if year10==1993 &obc_res_year==1991

gen q_casteyear=year10*10+ caste4
gen q_stateyear=STATEID*100+(year10-1947)

gen q_state_res_year=0
replace q_state_res_year=1 if year10>=obc_res_year

*continous
gen q_res_prop=0
replace q_res_prop=obcquota/stateobc if q_state_res_year==1
replace q_res_prop=20/stateobc if state=="Bihar" &year10 >=1977  &year14<1992
replace q_res_prop=20/stateobc if state=="Jharkhand" &year10>=1977  &year14<1993
replace q_res_prop=33/stateobc if state=="Jharkhand" &year10>= 1992 &year14<2000
replace q_res_prop=35/stateobc if state=="Karnataka" &year10>=1977  &year14<1996
replace q_res_prop=55/stateobc if state=="Karnataka" &year10>=1986  &year14<1994
replace q_res_prop=14/stateobc if state=="Maharashtra" &year10>=1947  &year14<1994
replace q_res_prop=30/stateobc if state=="Maharashtra" &year10>= 1994 &year14<1995
replace q_res_prop=5/stateobc if state=="Punjab" &year10>=1964  &year14<1993
replace q_res_prop=25/stateobc if state=="Tamil Nadu" &year10>=1947  &year14<1971
replace q_res_prop=31/stateobc if state=="Tamil Nadu" &year10>=1971  &year14<1980
replace q_res_prop=27/stateobc if state=="Uttarakhand" &year10>=1993  &year14<2000


gen q_res_prop_obc=obc*q_res_prop

gen q_int_obc=castgr 
gen q_int_post94=q_period
gen q_int_northstate=stategr
gen q_int_obc_north=castgr *stategr
gen q_int_obc_post94=castgr*q_period
gen q_int_north_post94=stategr*q_period
gen q_int_north_obc_post=castgr *stategr*q_period
gen q_obc_post79=0
replace q_obc_post79=1 if year10>1979&obc==1
gen q_north_post79=0
replace q_north_post79=1 if year10>1979&stategr==1


*22 year olds
gen year22=birthyear+21


gen v_period=0
replace v_period =1 if year22>1993
replace v_period=. if year18>1993





gen v_mandalcasteyear=0
replace v_mandalcasteyear=1 if v_period==1 &stategrp==1&castgrp==1
replace v_mandalcasteyear=. if year22==1991 &obc_res_year==1991&castgrp==1
replace v_mandalcasteyear=. if year22==1992 &obc_res_year==1991&castgrp==1
replace v_mandalcasteyear=. if year22==1993 &obc_res_year==1991&castgrp==1

gen v_yearmandal=0
replace v_yearmandal=1 if v_period==1 &stategrp==1
replace v_yearmandal=. if year22==1991 &obc_res_year==1991
replace v_yearmandal=. if year22==1992 &obc_res_year==1991
replace v_yearmandal=. if year22==1993 &obc_res_year==1991

gen v_casteyear=year22*10+ caste4
gen v_stateyear=STATEID*100+(year22-1947)

gen v_state_res_year=0
replace v_state_res_year=1 if year22>=obc_res_year

*continous
gen v_res_prop=0
replace v_res_prop=obcquota/stateobc if v_state_res_year==1
replace v_res_prop=20/stateobc if state=="Bihar" &year22 >=1977  &year22<1992
replace v_res_prop=20/stateobc if state=="Jharkhand" &year22>=1977  &year22<1993
replace v_res_prop=33/stateobc if state=="Jharkhand" &year22>= 1992 &year22<2000
replace v_res_prop=35/stateobc if state=="Karnataka" &year22>=1977  &year22<1996
replace v_res_prop=55/stateobc if state=="Karnataka" &year22>=1986  &year22<1994
replace v_res_prop=18/stateobc if state=="Maharashtra" &year22>=1947  &year22<1994
replace v_res_prop=30/stateobc if state=="Maharashtra" &year22>= 1994 &year22<1995
replace v_res_prop=5/stateobc if state=="Punjab" &year22>=1964  &year22<1993
replace v_res_prop=25/stateobc if state=="Tamil Nadu" &year22>=1947  &year22<1971
replace v_res_prop=31/stateobc if state=="Tamil Nadu" &year22>=1971  &year22<1980
replace v_res_prop=27/stateobc if state=="Uttarakhand" &year22>=1993  &year22<2000


gen v_res_prop_obc=obc*v_res_prop

gen v_int_obc=castgr 
gen v_int_post94=v_period
gen v_int_northstate=stategr
gen v_int_obc_north=castgr *stategr
gen v_int_obc_post94=castgr*v_period
gen v_int_north_post94=stategr*v_period
gen v_int_north_obc_post=castgr *stategr*v_period
gen v_obc_post79=0
replace v_obc_post79=1 if year22>1979&obc==1
gen v_north_post79=0
replace v_north_post79=1 if year22>1979&stategr==1


*26 year olds
gen year26=birthyear+25


gen u_period=0
replace u_period =1 if year26>1993
replace u_period=. if year18>1993





gen u_mandalcasteyear=0
replace u_mandalcasteyear=1 if u_period==1 &stategrp==1&castgrp==1
replace u_mandalcasteyear=. if year26==1991 &obc_res_year==1991&castgrp==1
replace u_mandalcasteyear=. if year26==1992 &obc_res_year==1991&castgrp==1
replace u_mandalcasteyear=. if year26==1993 &obc_res_year==1991&castgrp==1

gen u_yearmandal=0
replace u_yearmandal=1 if u_period==1 &stategrp==1
replace u_yearmandal=. if year26==1991 &obc_res_year==1991
replace u_yearmandal=. if year26==1992 &obc_res_year==1991
replace u_yearmandal=. if year26==1993 &obc_res_year==1991

gen u_casteyear=year26*10+ caste4
gen u_stateyear=STATEID*100+(year26-1947)

gen u_state_res_year=0
replace u_state_res_year=1 if year26>=obc_res_year

*continous
gen u_res_prop=0
replace u_res_prop=obcquota/stateobc if u_state_res_year==1
replace u_res_prop=20/stateobc if state=="Bihar" &year26 >=1977  &year26<1992
replace u_res_prop=20/stateobc if state=="Jharkhand" &year26>=1977  &year26<1993
replace u_res_prop=33/stateobc if state=="Jharkhand" &year26>= 1992 &year26<2000
replace u_res_prop=35/stateobc if state=="Karnataka" &year26>=1977  &year26<1996
replace u_res_prop=55/stateobc if state=="Karnataka" &year26>=1986  &year26<1994
replace u_res_prop=18/stateobc if state=="Maharashtra" &year26>=1947  &year26<1994
replace u_res_prop=30/stateobc if state=="Maharashtra" &year26>= 1994 &year26<1995
replace u_res_prop=5/stateobc if state=="Punjab" &year26>=1964  &year26<1993
replace u_res_prop=25/stateobc if state=="Tamil Nadu" &year26>=1947  &year26<1971
replace u_res_prop=31/stateobc if state=="Tamil Nadu" &year26>=1971  &year26<1980
replace u_res_prop=27/stateobc if state=="Uttarakhand" &year26>=1993  &year26<2000


gen u_res_prop_obc=obc*u_res_prop

gen u_int_obc=castgr 
gen u_int_post94=u_period
gen u_int_northstate=stategr
gen u_int_obc_north=castgr *stategr
gen u_int_obc_post94=castgr*u_period
gen u_int_north_post94=stategr*u_period
gen u_int_north_obc_post=castgr *stategr*u_period
gen u_obc_post79=0
replace u_obc_post79=1 if year26>1979&obc==1
gen u_north_post79=0
replace u_north_post79=1 if year26>1979&stategr==1



